package com.ssm.design.chain.handler;

import com.ssm.design.chain.OrderHandlerChain;
import com.ssm.design.chain.context.OrderHandleContext;
import com.ssm.design.common.dto.OrderDto;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import static com.ssm.design.common.constant.OrderConstant.ORDER_HANDLER_WEIGHT_COUPON;

@Order(ORDER_HANDLER_WEIGHT_COUPON)
@Component
public class CouponOrderHandler extends AbstractHandler {

    @Override
    public void doHandle(OrderHandleContext context, OrderHandlerChain chain) {
        OrderDto orderDto = context.getOrderDto();
        if (orderDto.getCouponNo() != null) {
            orderDto.setAmount(orderDto.getAmount() - 10);
        }
        // 调用下一个处理器进行处理
        chain.handle(context);
    }
}
